package com.theo.mapper;

import com.theo.entity.RefutationInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Repository
public interface RefutationInfoMapper extends BaseMapper<RefutationInfo> {

    @Insert("INSERT INTO `refutation_info`(`rumour_id`,`refutation_title`,`refutation_content`,`date`,`result`,`explain`,`author`,`user_id`)" +
            "VALUES(#{rumourId},#{refutationTitle},#{refutationContent},#{date},#{result},#{explain},#{author},#{userId})")
    int saveRefutationInfo(RefutationInfo refutationInfo);

    int deleteRefutationInfo(Integer id);

    int updateRefutationInfo(Integer id);

    @Select("SELECT r.`refutation_id`,r.`rumour_id`,r.`refutation_title`,r.`refutation_content`,r.`date`,r.`result`,r.`explain`,r.`author`,r.`user_id`,u.`user_name`,u.`login_name`\n" +
            "FROM `refutation_info` r INNER JOIN `user_info` u\n" +
            "ON r.`user_id`=u.`user_id` ORDER BY `date` DESC")
    List<RefutationInfo> queryAllRefutationInfo();

    @Select("SELECT * FROM `refutation_info` WHERE `refutation_id`=#{id}")
    RefutationInfo queryRefutationInfoById(Integer id);
}
